package com.projectName.www.servlet;

import com.projectName.www.dao.DishDao;
import com.projectName.www.dao.DishDaoImpl;
import com.projectName.www.po.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/deleteDishServlet")
public class DeleteDishServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");
        //2.获取参数

        String did = request.getParameter("did");
        HttpSession session=request.getSession();
        User user = (User)session.getAttribute("user");



        //4.调用Service保存
        DishDao dd=new DishDaoImpl();
        dd.delete(did);



        //5.跳转到userListServlet
        response.sendRedirect(request.getContextPath()+"/dishListServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
